import { applyMiddleware, legacy_createStore as createStore } from 'redux'
import rootReducer from './reducer'
import thunk from 'redux-thunk'
import { composeWithDevTools } from 'redux-devtools-extension'
import { useDispatch, TypedUseSelectorHook, useSelector } from "react-redux";

const store = createStore(rootReducer, composeWithDevTools(applyMiddleware(thunk)))

export type AppDispatch = typeof store.dispatch
export type RootState = ReturnType<typeof store.getState>

export const useAppDispatch: () => AppDispatch | any = useDispatch
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector

export default store
